package com.wx.mapper;

import com.wx.dto.RefineUserInfo;
import com.wx.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    //根据用户名查询账号
    @Select("select * from user where username = #{username}")
    User queryByUsername(String username);

    //添加用户
    @Insert("insert into user(username,password,name,email,phone,address,create_time,is_delete)" +
            "values(#{username},#{password},#{name},#{email},#{phone},#{address},#{createTime},#{isDelete})")
    void saveUser(User user);

    //用户修改个人信息和密码
    void updateUser(User user);

    //用户完善个人信息
    @Update("update user set name=#{name},email=#{email},phone=#{phone},address=#{address} where username = #{username}")
    void refineInfo(RefineUserInfo refineUserInfo);

    //用户注销账号
    @Update("update user set is_delete = 1 where username = #{username}")
    void deleteUser(User user);


    /*清除用户购物车和收藏数据*/
    @Delete("delete favor.*,`order`.* from favor,`order` where favor.username = #{username} and `order`.username = #{username}")
    void purge(User user);
}
